#!/usr/bin/env python
# -*- coding: utf-8 -*-

'''Module for parsing DIAB mapfiles'''
import re

def parse_diab(mapfile, outputfile):
    '''Function accepting the filename of a DIAB mapfile and returning a list of tuples'''
    matchlist = []
    with open(mapfile) as diab_map:
        for line in diab_map:
            regex = re.compile(r"^\s*(\.\w+)\s+([0-9a-fA-F]+)\s+([0-9a-fA-F]+)\s*$")
            match = regex.findall(line)
            if(match):
                matchtuple = (match[0][0], match[0][1], match[0][2])
                matchlist.append(matchtuple)
    objectlist = mem_section.convert_to_objects(matchlist)
    return objectlist



def diab_extract_labels(mapfile):
    '''Function accepting the filename of a DIAB mapfile and returning a list of tuples'''
    matchlist = []
    with open(mapfile) as diab_map:
        for line in diab_map:
            regex = re.compile(r"^\s*(\w+)\s([0-9a-fA-F]+)\s*$")
            match = regex.findall(line)
            if(match):
                matchtuple = (match[0][0], int(match[0][1], 16))
                matchlist.append(matchtuple)
    return matchlist

